package com.tuozixuan.jmh.demo;

import org.openjdk.jmh.runner.RunnerException;

public class OriginalWayDemo {
	
	static String a = "select id, name from user";
	
	static int count = 5000;

	public static void main(String[] args) throws RunnerException {
		
		long t1 = System.currentTimeMillis();
		concat();
		long t2 = System.currentTimeMillis();
		System.out.println("concat:" + (t2 - t1) + "ms");
		
		long t3 = System.currentTimeMillis();
		concatByBuilder();
		long t4 = System.currentTimeMillis();
		System.out.println("concatByBuilder:" + (t4 - t3) + "ms");
		
		long t5 = System.currentTimeMillis();
		concatByBuffer();
		long t6 = System.currentTimeMillis();
		System.out.println("concatByBuffer:" + (t6 - t5) + "ms");
	}
	
	public static String concat() {
		String c = "";
		for (int i = 0; i < count; i++) {
			c += a;
		}
		return c;
	}
	
	public static String concatByBuilder() {
		
		StringBuilder c = new StringBuilder();
		for (int i = 0; i < count; i++) {
			c.append(a);
		}
		return c.toString();
	}
	
	public static String concatByBuffer() {
		
		StringBuffer c = new StringBuffer();
		for (int i = 0; i < count; i++) {
			c.append(a);
		}
		return c.toString();
	}
}
